home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / fortran / f2c_src.zip / F2C / MAIN.C < prev    next >
C/C++ Source or Header  |  1991-06-10  |  17KB  |  589 lines

  1. /****************************************************************
  2. Copyright 1990 by AT&T Bell Laboratories and Bellcore.
  3.  
  4. Permission to use, copy, modify, and distribute this software
  5. and its documentation for any purpose and without fee is hereby
  6. granted, provided that the above copyright notice appear in all
  7. copies and that both that the copyright notice and this
  8. permission notice and warranty disclaimer appear in supporting
  9. documentation, and that the names of AT&T Bell Laboratories or
  10. Bellcore or any of their entities not be used in advertising or
  11. publicity pertaining to distribution of the software without
  12. specific, written prior permission.
  13.  
  14. AT&T and Bellcore disclaim all warranties with regard to this
  15. software, including all implied warranties of merchantability
  16. and fitness.  In no event shall AT&T or Bellcore be liable for
  17. any special, indirect or consequential damages or any damages
  18. whatsoever resulting from loss of use, data or profits, whether
  19. in an action of contract, negligence or other tortious action,
  20. arising out of or in connection with the use or performance of
  21. this software.
  22. ****************************************************************/
  23.  
  24. extern char F2C_version[];
  25.  
  26. #include "defs.h"
  27. #include "parse.h"
  28.  
  29. int complex_seen, dcomplex_seen;
  30.  
  31. LOCAL int Max_ftn_files;
  32.  
  33. char **ftn_files;
  34. int current_ftn_file = 0;
  35.  
  36. flag ftn66flag = NO;
  37. flag nowarnflag = NO;
  38. flag noextflag = NO;
  39. flag  no66flag = NO;        /* Must also set noextflag to this
  40.                        same value */
  41. flag zflag = YES;        /* recognize double complex intrinsics */
  42. flag debugflag = NO;
  43. flag onetripflag = NO;
  44. flag shiftcase = YES;
  45. flag undeftype = NO;
  46. flag checksubs = NO;
  47. flag r8flag = NO;
  48. flag use_bs = YES;
  49. int tyreal = TYREAL;
  50. extern void r8fix(), read_Pfiles();
  51.  
  52. int maxregvar = MAXREGVAR;    /* if maxregvar > MAXREGVAR, error */
  53. int maxequiv = MAXEQUIV;
  54. int maxext = MAXEXT;
  55. int maxstno = MAXSTNO;
  56. int maxctl = MAXCTL;
  57. int maxhash = MAXHASH;
  58. int maxliterals = MAXLITERALS;
  59. int extcomm, ext1comm, useauto;
  60. int can_include = YES;    /* so we can disable includes for netlib */
  61.  
  62. static char *def_i2 = "";
  63.  
  64. static int useshortints = NO;    /* YES => tyint = TYSHORT */
  65. static int uselongints = NO;    /* YES => tyint = TYLONG */
  66. int addftnsrc = NO;        /* Include ftn source in output */
  67. int usedefsforcommon = NO;    /* Use #defines for common reference */
  68. int forcedouble = YES;        /* force real functions to double */
  69. int Ansi = NO;
  70. int def_equivs = YES;
  71. int tyioint = TYLONG;
  72. int szleng = SZLENG;
  73. int inqmask = M(TYLONG)|M(TYLOGICAL);
  74. int wordalign = NO;
  75. int forcereal = NO;
  76. static int skipC, skipversion;
  77. char *filename0, *parens;
  78. int Castargs = 1;
  79. static int typedefs = 0;
  80. int chars_per_wd, gflag, protostatus;
  81. int infertypes = 1;
  82. char used_rets[TYSUBR+1];
  83. extern char *tmpdir;
  84. static int h0align = 0;
  85. char *halign, *ohalign;
  86. int krparens = NO;
  87. int hsize;    /* for padding under -h */
  88. int htype;    /* for wr_equiv_init under -h */
  89.  
  90. #define f2c_entry(swit,count,type,store,size) \
  91.     p_entry ("-", swit, 0, count, type, store, size)
  92.  
  93. static arg_info table[] = {
  94.     f2c_entry ("w66", P_NO_ARGS, P_INT, &ftn66flag, YES),
  95.     f2c_entry ("w", P_NO_ARGS, P_INT, &nowarnflag, YES),
  96.     f2c_entry ("66", P_NO_ARGS, P_INT, &no66flag, YES),
  97.     f2c_entry ("d", P_ONE_ARG, P_INT, &debugflag, YES),
  98.     f2c_entry ("1", P_NO_ARGS, P_INT, &onetripflag, YES),
  99.     f2c_entry ("onetrip", P_NO_ARGS, P_INT, &onetripflag, YES),
  100.     f2c_entry ("I2", P_NO_ARGS, P_INT, &useshortints, YES),
  101.     f2c_entry ("I4", P_NO_ARGS, P_INT, &uselongints, YES),
  102.     f2c_entry ("U", P_NO_ARGS, P_INT, &shiftcase, NO),
  103.     f2c_entry ("u", P_NO_ARGS, P_INT, &undeftype, YES),
  104.     f2c_entry ("O", P_ONE_ARG, P_INT, &maxregvar, 0),
  105.     f2c_entry ("C", P_NO_ARGS, P_INT, &checksubs, YES),
  106.     f2c_entry ("Nq", P_ONE_ARG, P_INT, &maxequiv, 0),
  107.     f2c_entry ("Nx", P_ONE_ARG, P_INT, &maxext, 0),
  108.     f2c_entry ("Ns", P_ONE_ARG, P_INT, &maxstno, 0),
  109.     f2c_entry ("Nc", P_ONE_ARG, P_INT, &maxctl, 0),
  110.     f2c_entry ("Nn", P_ONE_ARG, P_INT, &maxhash, 0),
  111.     f2c_entry ("NL", P_ONE_ARG, P_INT, &maxliterals, 0),
  112.     f2c_entry ("c", P_NO_ARGS, P_INT, &addftnsrc, YES),
  113.     f2c_entry ("p", P_NO_ARGS, P_INT, &usedefsforcommon, YES),
  114.     f2c_entry ("R", P_NO_ARGS, P_INT, &forcedouble, NO),
  115.     f2c_entry ("!R", P_NO_ARGS, P_INT, &forcedouble, YES),
  116.     f2c_entry ("A", P_NO_ARGS, P_INT, &Ansi, YES),
  117.     f2c_entry ("ext", P_NO_ARGS, P_INT, &noextflag, YES),
  118.     f2c_entry ("z", P_NO_ARGS, P_INT, &zflag, NO),
  119.     f2c_entry ("a", P_NO_ARGS, P_INT, &useauto, YES),
  120.     f2c_entry ("r8", P_NO_ARGS, P_INT, &r8flag, YES),
  121.     f2c_entry ("i2", P_NO_ARGS, P_INT, &tyioint, NO),
  122.     f2c_entry ("w8", P_NO_ARGS, P_INT, &wordalign, YES),
  123.     f2c_entry ("!I", P_NO_ARGS, P_INT, &can_include, NO),
  124.     f2c_entry ("W", P_ONE_ARG, P_INT, &chars_per_wd, 0),
  125.     f2c_entry ("g", P_NO_ARGS, P_INT, &gflag, YES),
  126.     f2c_entry ("T", P_ONE_ARG, P_STRING, &tmpdir, 0),
  127.     f2c_entry ("E", P_NO_ARGS, P_INT, &extcomm, 1),
  128.     f2c_entry ("e1c", P_NO_ARGS, P_INT, &ext1comm, 1),
  129.     f2c_entry ("ec", P_NO_ARGS, P_INT, &ext1comm, 2),
  130.     f2c_entry ("C++", P_NO_ARGS, P_INT, &Ansi, 2),
  131.     f2c_entry ("P", P_NO_ARGS, P_INT, &Castargs, 3),
  132.     f2c_entry ("Ps", P_NO_ARGS, P_INT, &protostatus, 1),
  133.     f2c_entry ("!P", P_NO_ARGS, P_INT, &Castargs, 0),
  134.     f2c_entry ("!c", P_NO_ARGS, P_INT, &skipC, 1),
  135.     f2c_entry ("!it", P_NO_ARGS, P_INT, &infertypes, 0),
  136.     f2c_entry ("h", P_NO_ARGS, P_INT, &h0align, 1),
  137.     f2c_entry ("hd", P_NO_ARGS, P_INT, &h0align, 2),
  138.     f2c_entry ("kr", P_NO_ARGS, P_INT, &krparens, 1),
  139.     f2c_entry ("krd", P_NO_ARGS, P_INT, &krparens, 2),
  140.     f2c_entry ("!bs", P_NO_ARGS, P_INT, &use_bs, NO),
  141.     f2c_entry ("r", P_NO_ARGS, P_INT, &forcereal, YES),
  142.  
  143.     /* options omitted from man pages */
  144.  
  145.     /* -ev ==> implement equivalence with initialized pointers */
  146.     f2c_entry ("ev", P_NO_ARGS, P_INT, &def_equivs, NO),
  147.  
  148.     /* -!it used to be the default when -it was more agressive */
  149.  
  150.     f2c_entry ("it", P_NO_ARGS, P_INT, &infertypes, 1),
  151.  
  152.     /* -Pd is similar to -P, but omits :ref: lines */
  153.     f2c_entry ("Pd", P_NO_ARGS, P_INT, &Castargs, 2),
  154.  
  155.     /* -t ==> emit typedefs (under -A or -C++) for procedure
  156.         argument types used.  This is meant for netlib's
  157.         f2c service, so -A and -C++ will work with older
  158.         versions of f2c.h
  159.         */
  160.     f2c_entry ("t", P_NO_ARGS, P_INT, &typedefs, 1),
  161.  
  162.     /* -!V ==> omit version msg (to facilitate using diff in
  163.         regression testing)
  164.         */
  165.     f2c_entry ("!V", P_NO_ARGS, P_INT, &skipversion, 1)
  166.  
  167. }; /* table */
  168.  
  169. extern char *c_functions;    /* "c_functions"    */
  170. extern char *coutput;        /* "c_output"        */
  171. extern char *initfname;        /* "raw_data"        */
  172. extern char *blkdfname;        /* "block_data"        */
  173. extern char *p1_file;        /* "p1_file"        */
  174. extern char *p1_bakfile;    /* "p1_file.BAK"    */
  175. extern char *sortfname;        /* "init_file"        */
  176. static char *proto_fname;    /* "proto_file"        */
  177. FILE *protofile;
  178.  
  179. extern void list_init_data(), set_tmp_names(), sigcatch(), Un_link_all();
  180. extern char *c_name();
  181.  
  182.  
  183. set_externs ()
  184. {
  185.     static char *hset[3] = { 0, "integer", "doublereal" };
  186.  
  187. /* Adjust the global flags according to the command line parameters */
  188.  
  189.     if (chars_per_wd > 0) {
  190.     typesize[TYADDR] = typesize[TYLONG] = typesize[TYREAL] =
  191.         typesize[TYLOGICAL] = chars_per_wd;
  192.     typesize[TYDREAL] = typesize[TYCOMPLEX] = chars_per_wd << 1;
  193.     typesize[TYDCOMPLEX] = chars_per_wd << 2;
  194.     typesize[TYSHORT] = chars_per_wd >> 1;
  195.     typesize[TYCILIST] = 5*chars_per_wd;
  196.     typesize[TYICILIST] = 6*chars_per_wd;
  197.     typesize[TYOLIST] = 9*chars_per_wd;
  198.     typesize[TYCLLIST] = 3*chars_per_wd;
  199.     typesize[TYALIST] = 2*chars_per_wd;
  200.     typesize[TYINLIST] = 26*chars_per_wd;
  201.     }
  202.  
  203.     if (wordalign)
  204.     typealign[TYDREAL] = typealign[TYDCOMPLEX] = typealign[TYREAL];
  205.     if (!tyioint) {
  206.     tyioint = TYSHORT;
  207.     szleng = typesize[TYSHORT];
  208.     def_i2 = "#define f2c_i2 1\n";
  209.     inqmask = M(TYSHORT)|M(TYLOGICAL);
  210.     goto checklong;
  211.     }
  212.     else
  213.     szleng = typesize[TYLONG];
  214.     if (useshortints) {
  215.     inqmask = M(TYLONG);
  216.  checklong:
  217.     protorettypes[TYLOGICAL] = typename[TYLOGICAL] = "sho